home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MacAutoRepeatButton.java < prev    next >
Text File  |  1998-06-30  |  2KB  |  86 lines

  1. /*
  2.  * @(#)MacAutoRepeatButton.java    1.3 98/02/02
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.mac;
  22.  
  23. import java.awt.*;
  24. import java.awt.event.*;
  25. import com.sun.java.swing.*;
  26. import com.sun.java.swing.border.*;
  27. import com.sun.java.swing.plaf.*;
  28.  
  29. /**
  30.  * This button repeatedly fires action events when it is 
  31.  * held down.
  32.  *
  33.  * @version 1.0 01/20/98
  34.  */
  35. class MacAutoRepeatButton extends JButton {
  36.  
  37.   Timer timer = new Timer(30, null);
  38.   
  39.   public MacAutoRepeatButton (Icon icon) {
  40.       super(icon);
  41.       timer.setInitialDelay( 125 );
  42.   }
  43.  
  44.   public MacAutoRepeatButton() {
  45.       super();
  46.       timer.setInitialDelay( 125 );
  47.   }
  48.  
  49.   public void addActionListener(ActionListener l ) {
  50.       super.addActionListener(l);
  51.       timer.addActionListener(l);
  52.   }
  53.  
  54.   public void removeActionListener(ActionListener l ) {
  55.       super.removeActionListener(l);
  56.       timer.removeActionListener(l);
  57.   }
  58.  
  59.   public void setRepeatInterval(int interval) {
  60.       timer.setDelay(interval);
  61.   }
  62.  
  63.   public int getRepeatInterval() {
  64.       return timer.getDelay();
  65.   }
  66.  
  67.   protected void processMouseEvent(MouseEvent e) {
  68.     if (e.getID() == e.MOUSE_CLICKED ) {
  69.         super.processMouseEvent(e);
  70.     return;
  71.     }    
  72.     if (e.getID() == e.MOUSE_PRESSED ) {
  73.         model.setArmed(true);
  74.         model.setPressed(true);
  75.         repaint();
  76.         timer.start();
  77.     }
  78.     if (e.getID() == e.MOUSE_RELEASED ||
  79.         e.getID() == e.MOUSE_EXITED) {
  80.         model.setPressed(false);
  81.         repaint();
  82.         timer.stop();
  83.     }    
  84.   }
  85. }
  86.